package schedulo.core.task.provider;

import schedulo.core.task.provider.parameters.Parameters;
import schedulo.core.task.provider.parameters.ParametersException;

public class Spec {

	public static final String ARGS_DELIMITER = ":";

	private String name;

	private Parameters parameters;

	public Spec(String spec) throws ParametersException {

		spec = spec.toLowerCase();
		
		// parse the spec
		if (spec.contains(ARGS_DELIMITER)) {
			name = spec.substring(0, spec.indexOf(ARGS_DELIMITER)).trim();

			spec = spec.substring(spec.indexOf(ARGS_DELIMITER) + 1);
			parameters = new Parameters(spec);
		} else {
			name = spec.trim();
			parameters = new Parameters(null);
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean hasParameters() {
		return parameters != null;
	}
	
	public Parameters getParameters() {
		return parameters;
	}
	
	public void setParameters(Parameters params) {
		parameters = params;
	}
	
	public String toString() {
		return name + ":" + parameters.toString();
	}
}
